/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Screens;

import Controllers.HdChamadosJpaController;
import Controllers.HdEquipamentoJpaController;
import Controllers.HdTipoProblemaJpaController;
import Controllers.HdUsersJpaController;
import Controllers.exceptions.NonexistentEntityException;
import Entities.HdChamados;
import Entities.HdEquipamento;
import Entities.HdTipoProblema;
import Util.Constantes;
import Util.EMFConection;
import Util.StatusChamado;
import Util.UserLogado;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Douglas
 */
public class EditarChamados extends javax.swing.JFrame {

    /**
     * Creates new form EditarChamados
     */
    private EditarChamados() {
    }
    public EditarChamados(HdChamados chamados) {
        initComponents();
        popularComboBox();
        this.chamado = chamados;
        this.statusChamado = chamados.getStChamado();           
        editar(chamado);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    private void popularComboBox(){
        HdEquipamentoJpaController EquipamentoJpaController = new HdEquipamentoJpaController(EMFConection.getInstance());
        List<HdEquipamento> list = EquipamentoJpaController.findHdEquipamentoEntities();
        for (HdEquipamento Equipamento : list) {
            cbEquipamento.addItem(Equipamento.getDeEquipamento());
        }
        
        HdTipoProblemaJpaController tipoProblemaJpaController = new HdTipoProblemaJpaController(EMFConection.getInstance());
        List<HdTipoProblema> lista = tipoProblemaJpaController.findHdTipoProblemaEntities();
        for (HdTipoProblema tipoProblema : lista) {
            cbTipoProblema.addItem(tipoProblema.getDeTipoProblema());
        }
    }
    
    private void editar(HdChamados chamados){
        
        tfCodChamado.setText(String.valueOf(chamados.getCoChamado()));
        tfNomeUsuario.setText(chamados.getCoUserResp().getNmUser());
        cbEquipamento.setSelectedItem(chamados.getCoEquipamento().getDeEquipamento());
        
        
        popularStatus(chamados.getStChamado());
        
        try{
            tfNomeUsuarioSuporte.setText(chamados.getCoUserSuporte().getNmUser());
        }catch(Exception e){
            tfNomeUsuarioSuporte.setText(Constantes.STRING_VAZIA);
        }
        try{
            ftfCriacaoChamado.setText(sdf.format(chamados.getDtCriacaoChamado()));
        }catch(Exception e){
            ftfCriacaoChamado.setText(Constantes.STRING_VAZIA);
        }
        try{
            ftfInicioSuporte.setText(sdf.format(chamados.getDtInicioSuporte()));  
        }catch(Exception e){
            ftfInicioSuporte.setText(Constantes.STRING_VAZIA);
        }
        try{
            ftfTerminoSuporte.setText(sdf.format(chamados.getDtFinalizacaoSuporte()));
        }catch(Exception e){
            ftfTerminoSuporte.setText(Constantes.STRING_VAZIA);
        }
        cbTipoProblema.setSelectedItem(chamados.getCoTipoProblema().getDeTipoProblema());
        taDescricaoChamado.setText(chamados.getDeChamado());
        taDescricaoSolucao.setText(chamados.getDeSolucao());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbChamados = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        lbEquipamento = new javax.swing.JLabel();
        lbNomeUsuario = new javax.swing.JLabel();
        tfNomeUsuario = new javax.swing.JTextField();
        lbStatus = new javax.swing.JLabel();
        lbCodChamado = new javax.swing.JLabel();
        tfCodChamado = new javax.swing.JTextField();
        cbEquipamento = new javax.swing.JComboBox();
        lbStatusChamado = new javax.swing.JLabel();
        btAlterarChamado = new javax.swing.JButton();
        tfNomeUsuarioSuporte = new javax.swing.JTextField();
        lbNomeUsuarioSuporte = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        ftfCriacaoChamado = new javax.swing.JFormattedTextField();
        ftfInicioSuporte = new javax.swing.JFormattedTextField();
        lbTerminoSuporte = new javax.swing.JLabel();
        ftfTerminoSuporte = new javax.swing.JFormattedTextField();
        lbCriacaoChamado = new javax.swing.JLabel();
        lbInicioSuporte = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jPanel3 = new javax.swing.JPanel();
        lbTipoProblema = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        taDescricaoChamado = new javax.swing.JTextPane();
        lbDescricaoSolucao = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taDescricaoSolucao = new javax.swing.JTextPane();
        lbDescricaoChamado = new javax.swing.JLabel();
        cbTipoProblema = new javax.swing.JComboBox();
        btCancelar = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Help Desk");
        setResizable(false);

        lbChamados.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbChamados.setText("Chamados:");

        lbEquipamento.setText("Equipamento:");

        lbNomeUsuario.setText("Nome do Usuário:");

        tfNomeUsuario.setEnabled(false);

        lbStatus.setText("Status Atual:");

        lbCodChamado.setText("Código Chamado:");

        tfCodChamado.setEnabled(false);

        lbStatusChamado.setText("Invalido");

        btAlterarChamado.setText("Alterar");
        btAlterarChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarChamadoActionPerformed(evt);
            }
        });

        tfNomeUsuarioSuporte.setEnabled(false);

        lbNomeUsuarioSuporte.setText("Nome do Usuário do Suporte:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbStatus)
                                    .addComponent(lbEquipamento))
                                .addGap(63, 63, 63))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(lbCodChamado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lbNomeUsuario)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbStatusChamado)
                        .addGap(18, 18, 18)
                        .addComponent(btAlterarChamado, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(cbEquipamento, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfCodChamado, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(tfNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbNomeUsuarioSuporte)
                        .addGap(18, 18, 18)
                        .addComponent(tfNomeUsuarioSuporte, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(71, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCodChamado)
                    .addComponent(tfCodChamado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNomeUsuario)
                    .addComponent(lbNomeUsuarioSuporte)
                    .addComponent(tfNomeUsuarioSuporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbEquipamento)
                    .addComponent(cbEquipamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbStatus)
                    .addComponent(lbStatusChamado)
                    .addComponent(btAlterarChamado))
                .addContainerGap())
        );

        ftfCriacaoChamado.setEnabled(false);

        ftfInicioSuporte.setEnabled(false);

        lbTerminoSuporte.setText("Término do Suporte:");

        ftfTerminoSuporte.setEnabled(false);

        lbCriacaoChamado.setText("Criação do Chamado:");

        lbInicioSuporte.setText("Inicio Suporte:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbCriacaoChamado)
                    .addComponent(lbInicioSuporte))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(ftfInicioSuporte, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(lbTerminoSuporte)
                        .addGap(18, 18, 18)
                        .addComponent(ftfTerminoSuporte, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(ftfCriacaoChamado, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCriacaoChamado)
                    .addComponent(ftfCriacaoChamado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbInicioSuporte)
                    .addComponent(lbTerminoSuporte)
                    .addComponent(ftfTerminoSuporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftfInicioSuporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        lbTipoProblema.setText("Tipo de Problema:");

        jScrollPane2.setViewportView(taDescricaoChamado);

        lbDescricaoSolucao.setText("Descrição de Chamado:");

        jScrollPane1.setViewportView(taDescricaoSolucao);

        lbDescricaoChamado.setText("Descrição da Solução:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbTipoProblema)
                    .addComponent(lbDescricaoSolucao)
                    .addComponent(lbDescricaoChamado))
                .addGap(19, 19, 19)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cbTipoProblema, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbTipoProblema, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbTipoProblema))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbDescricaoSolucao)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbDescricaoChamado)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        btCancelar.setText("Cancelar");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(jSeparator2)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbChamados)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbChamados)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancelar)
                    .addComponent(btSalvar))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-729)/2, (screenSize.height-637)/2, 729, 637);
    }// </editor-fold>//GEN-END:initComponents

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        HdChamadosJpaController chamadosJpaController = new HdChamadosJpaController(EMFConection.getInstance());
        HdEquipamentoJpaController equipamentoJpaController = new HdEquipamentoJpaController(EMFConection.getInstance());
        HdTipoProblemaJpaController tipoProblemaJpaController = new HdTipoProblemaJpaController(EMFConection.getInstance());
        HdUsersJpaController usersJpaController = new HdUsersJpaController(EMFConection.getInstance());
        
        chamado.setCoEquipamento(equipamentoJpaController.findHdEquipamento(cbEquipamento.getSelectedIndex()+1));
        chamado.setCoTipoProblema(tipoProblemaJpaController.findHdTipoProblema(cbTipoProblema.getSelectedIndex()+1));        
        chamado.setDeChamado(taDescricaoSolucao.getText());
        chamado.setDeSolucao(taDescricaoChamado.getText());
        try {
            chamado.setDtCriacaoChamado(sdf.parse(ftfCriacaoChamado.getText()));
        } catch (ParseException ex) {
            chamado.setDtCriacaoChamado(null);
        }
        try {
            chamado.setDtFinalizacaoSuporte(sdf.parse(ftfTerminoSuporte.getText()));
        } catch (ParseException ex) {
            chamado.setDtFinalizacaoSuporte(null);
        }
        try {
            chamado.setDtInicioSuporte(sdf.parse(ftfInicioSuporte.getText()));
        } catch (ParseException ex) {
            chamado.setDtInicioSuporte(null);
        }
        chamado.setStChamado(this.statusChamado);
        
        try {
            chamadosJpaController.edit(chamado);
            this.dispose();
        } catch (NonexistentEntityException ex) {
            Logger.getLogger(EditarChamados.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(EditarChamados.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    private void btAlterarChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAlterarChamadoActionPerformed
        this.statusChamado+=1;
        popularStatus(this.statusChamado);
    }//GEN-LAST:event_btAlterarChamadoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JButton btAlterarChamado;
    protected javax.swing.JButton btCancelar;
    protected javax.swing.JButton btSalvar;
    protected javax.swing.JComboBox cbEquipamento;
    protected javax.swing.JComboBox cbTipoProblema;
    protected javax.swing.JFormattedTextField ftfCriacaoChamado;
    protected javax.swing.JFormattedTextField ftfInicioSuporte;
    protected javax.swing.JFormattedTextField ftfTerminoSuporte;
    protected javax.swing.JPanel jPanel1;
    protected javax.swing.JPanel jPanel2;
    protected javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    protected javax.swing.JSeparator jSeparator1;
    protected javax.swing.JSeparator jSeparator2;
    protected javax.swing.JLabel lbChamados;
    private javax.swing.JLabel lbCodChamado;
    private javax.swing.JLabel lbCriacaoChamado;
    private javax.swing.JLabel lbDescricaoChamado;
    private javax.swing.JLabel lbDescricaoSolucao;
    private javax.swing.JLabel lbEquipamento;
    private javax.swing.JLabel lbInicioSuporte;
    public javax.swing.JLabel lbNomeUsuario;
    public javax.swing.JLabel lbNomeUsuarioSuporte;
    private javax.swing.JLabel lbStatus;
    protected javax.swing.JLabel lbStatusChamado;
    private javax.swing.JLabel lbTerminoSuporte;
    private javax.swing.JLabel lbTipoProblema;
    protected javax.swing.JTextPane taDescricaoChamado;
    protected javax.swing.JTextPane taDescricaoSolucao;
    protected javax.swing.JTextField tfCodChamado;
    protected javax.swing.JTextField tfNomeUsuario;
    protected javax.swing.JTextField tfNomeUsuarioSuporte;
    // End of variables declaration//GEN-END:variables

    private HdChamados chamado;
    private int statusChamado;
    private SimpleDateFormat sdf = new SimpleDateFormat(Constantes.FORMATO_DATA);
    
    private void popularStatus(Integer stChamado) {
        lbStatusChamado.setText(StatusChamado.getStatusByCod(stChamado));
        switch(stChamado){
            case 1:
                btAlterarChamado.setText(Constantes.BOTAO_ABRIR_CHAMADO);
                break;
            case 2:
                btAlterarChamado.setText(Constantes.BOTAO_FECHAR_CHAMADO);
                this.chamado.setCoUserSuporte(UserLogado.getInstance());
               if(chamado.getDtInicioSuporte() == null){ 
                   chamado.setDtInicioSuporte(new Date());
                   ftfInicioSuporte.setText(sdf.format(chamado.getDtInicioSuporte()));
                }
                break;
            case 3:
                btAlterarChamado.setVisible(false);
                if(chamado.getDtFinalizacaoSuporte() == null){ 
                    chamado.setDtFinalizacaoSuporte(new Date());
                    ftfTerminoSuporte.setText(sdf.format(chamado.getDtFinalizacaoSuporte()));
                }
                break;
        }
    }
}
